#include "scene.h"

scene::scene(QWidget *parent) : QLabel(parent)
{
    this->clear();
}
void scene::mousePressEvent(QMouseEvent *p)
{
    this->fig=false;
    this->x=p->position().x();
    this->y=p->position().y();
    QRect q(1,2,3,4);
    QPaintEvent event(q);
    QCoreApplication::sendEvent(this,&event);
    this->record.add(this->x,this->height()-this->y);

}
void scene::tranfig()
{
    this->fig=true;
}
 void scene::paintEvent(QPaintEvent *p)
 {
     QLabel::paintEvent(p);
     QPainter q(this);
     QPen pen;
     QColor color;
     color.setRgb(255,0,0);
     pen.setColor(color);
     pen.setWidth(3);
     q.setPen(pen);
     q.drawPoint(this->x,this->y);
     update();
 }
 void scene::write(QString file,double x0,double t0,double xu,double y0,double t1,double yu)
 {
     FILE *fp=fopen(file.toLocal8Bit().constData(),"w");
     if(fp)
     {
         while(this->record.getLength())
         {
             double temp1=0,temp2=0;
             this->record.del(temp1,temp2);
             fprintf(fp,"%lf\t%lf\n",(temp1-x0)*t0/(xu-x0),(temp2-y0)*t1/(yu-y0));
         }
     }
     QMessageBox::information(this,"提示","导出成功，请在文件中查看");
     fclose(fp);
 }
void scene::getx(double& x1,double& x2)
{
    x1=this->record.x[0];
    x2=this->record.x[1];
}
void scene::gety(double& y1,double& y2)
{
    y1=this->record.y[0];
    y2=this->record.y[1];
}
void scene::geto(double& o1,double& o2)
{
    o1=this->record.origin[0];
    o2=this->record.origin[1];
}

